﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SZSLSystem.Web.Admin.DataDictionary
{
    public partial class Edit : SZSLSystem.Web.UI.ManagePage
    {
        /// <summary>
        /// 页面初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.Params["ID"]))
            {
                JscriptMsg(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }
            if (!Page.IsPostBack)
            {
                Guid id = Guid.Parse(Request.Params["ID"]);
                ShowInfo(id);
            }
        }

       /// <summary>
        /// 赋值操作
       /// </summary>
       /// <param name="id">管理员编号</param>
        private void ShowInfo(Guid id)
        {
            SZSLSystem.BLL.DataDictionary bll = new SZSLSystem.BLL.DataDictionary();
            SZSLSystem.Model.DataDictionary model = bll.GetModel(id);
            if (model.ParentID != Guid.Parse(DataDictionaryID))
            {
                this.lblPname.Text = bll.GetModel(model.ParentID.Value).TypeName;
            }
            else
            {
                this.lblPname.Text = "数据字典";
            }
            this.txtName.Text = model.TypeName;
            this.txtDataCode.Text = model.DataCode;
            this.txtDescription.Text = model.Description;
            this.txtSortId.Text = model.Sort.ToString();
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                SZSLSystem.BLL.DataDictionary bll = new BLL.DataDictionary();
                SZSLSystem.Model.DataDictionary model = bll.GetModel(Guid.Parse(Request.Params["ID"]));
                model.DataCode = this.txtDataCode.Text.Trim();
                model.TypeName = this.txtName.Text.Trim();
                model.Description = this.txtDescription.Text.Trim();
                model.Sort = int.Parse(this.txtSortId.Text.Trim());
                bll.Update(model);
                //
                //日志写入
                //
                SaveLogs("修改数据字典成功！", 0);

                JscriptPrint("修改数据字典成功啦！", "List.aspx", "Success");
            }
            catch (Exception err)
            {
                //
                //异常日志写入
                //
                SaveLogs(err.ToString(), 1);

                JscriptMsg(350, 230, "错误提示", "<b>出现错误了！</b>修改数据字典失败！", "List.aspx", "Error");
            }
        }
    }
}
